const request = (options = {}) => {
  const defaultOptions = {
    loading: true,
    loadingText: '加载中...',
    url: '',
    method: 'GET',
    data: {},
    header: {},
    complete: () => {}
    // 其他可能用到的配置...
  }
 
  // 深拷贝避免外部修改options对象
  const optionsCopy = JSON.parse(JSON.stringify(options))
  const newOptions = { ...defaultOptions, ...optionsCopy }
 
  if (newOptions.loading) {
    uni.showLoading({
      title: newOptions.loadingText,
      mask: true
    })
  }
 
  return new Promise((resolve, reject) => {
    uni.request({
      ...newOptions,
      success: (response) => {
        // 请求成功处理逻辑
        resolve(response)
      },
      fail: (error) => {
        // 请求失败处理逻辑
        reject(error)
      },
      complete: (complete) => {
        // 请求完成处理逻辑
        if (newOptions.loading) {
          uni.hideLoading()
        }
        newOptions.complete(complete)
      }
    })
  })
}
 
export default request